package com.yanqu.road.server.manager.activity.biaoju;

import com.yanqu.road.entity.activity.ActivityConfig;
import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.enums.eActivityType;
import com.yanqu.road.logic.activity.biaoju.BiaoJuConfig;
import com.yanqu.road.logic.bussiness.servercenter.ActivityBussiness;
import com.yanqu.road.server.TempCrossMgr;
import com.yanqu.road.server.manager.activity.ActivityMgr;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class CrossBiaoJuConfigMgr extends TempCrossMgr {

    private static Map<Integer, BiaoJuConfig> configMap = new HashMap<>();

    @Override
    public boolean removeExpireData() throws Exception {
        return true;
    }

    @Override
    public boolean init() throws Exception {
        return reload();
    }

    @Override
    public boolean reloadConfig() throws Exception {
        return true;
    }

    @Override
    public boolean reloadData() throws Exception {
        return true;
    }

    @Override
    public boolean stop() {
        return true;
    }

    public static BiaoJuConfig getBiaoJuConfig(int activityId) {
        return configMap.get(activityId);
    }

    public static BiaoJuConfig reloadBiaoJuConfig(int activityId) {
        ActivityInfo activityInfo = ActivityMgr.getActivityInfoMayLoadDB(activityId);
        if (activityInfo == null) {
            return null;
        }

        if (activityInfo.getType() != eActivityType.BiaoJu.getValue()) {
            return null;
        }

        List<Integer> activityIdList = new ArrayList<>();
        activityIdList.add(activityId);
        Map<String, ActivityConfig> activityConfigMap = ActivityBussiness.getActivityConfigMap(activityIdList).get(activityId);

        BiaoJuConfig biaoJuConfig = new BiaoJuConfig(activityInfo, activityConfigMap);
        configMap.put(activityId, biaoJuConfig);
        return biaoJuConfig;
    }
}
